#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QImage>
#include <QPixmap>
#include <QPrinter>
#include <QPrintDialog>
#include "imageWorker.h"
#include "uartWorker.h"
#include "settings.h"

// 前向声明
class QLabel;
class QPushButton;
class QSlider;
class QComboBox;

class MainWindow : public QMainWindow {
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

    DetectionSettings detectionSettings;
    ResultSettings resultSettings;

signals:
    void openSerial(const QString &portName, int baudRate);
    void closeSerial();
    void sendData(const QByteArray &data);
    void receiveData();

private slots:
    // void openCamera();
    // void filterImage();
    void reset();
    void scanSerialPorts();      // 扫描串口
    void toggleOpenSerial(bool); // 打开/关闭串口

private:
    // 线程管理
    QThread *imageWorkerThread;
    QThread *uartWorkerThread;
    imageWorker *imageworker;
    uartWorker *uartworker;

    // UI组件
    QWidget *centralWidget;
    QLabel *imageLabel;
    QLabel *statusLabel;
    QPushButton *btnOpenCamera;
    QPushButton *btnDetect;
    QPushButton *btnReset;

    // 开关组件
    QPushButton *btnPassenger;
    QPushButton *btnSpark;
    QPushButton *btnIntruder;

    // 串口控制组件
    QComboBox *comboPort;
    QComboBox *comboBaud;
    QPushButton *btnScanPort;
    QPushButton *btnOpenPort;

    // 初始化UI
    void initUI();

    // 显示图像
    void displayImage(const QImage &image);
};

#endif // MAINWINDOW_H
